package com.emapp.lccode.http

import com.emapp.lccode.base.BaseConfig
import com.emapp.lccode.bean.ApiResponse
import com.emapp.lccode.bean.CommTypeKt
import com.emapp.lccode.bean.CountHome
import com.emapp.lccode.bean.DeviceKt
import com.emapp.lccode.bean.DistrictKt
import com.emapp.lccode.bean.Gongxu
import com.emapp.lccode.bean.MaterialKt
import com.emapp.lccode.bean.OrderKt
import com.emapp.lccode.bean.ProblemTypeKt
import com.emapp.lccode.bean.Project
import com.emapp.lccode.bean.UpFileKt
import com.emapp.lccode.bean.UserKt
import com.emapp.lccode.bean.VersionKt
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.http.*

/**
 * 描述　: 网络API
 */
interface ApiService {

    companion object {
        val SERVER_URL = BaseConfig.ROOT_URL
        const val SERVER_URL1 = "https://wanandroid.com/"
    }

    /**
     * 登录
     */
    @FormUrlEncoded
    @POST("/api/appapi/login")
    suspend fun login(
        @Field("username") username: String,
        @Field("verify_code") verify_code: String,
        @Field("img_verify") img_verify: String

    ): ApiResponse<Any>

    @POST("/api/appapi/addVerify")
    @Streaming
    suspend fun imageCode(): ResponseBody

    /**
     * 注册
     */
    @FormUrlEncoded
    @POST("user/register")
    suspend fun register(
        @Field("username") username: String, @Field("password") pwd: String, @Field(
            "repassword"
        ) rpwd: String
    ): ApiResponse<Any>

    @FormUrlEncoded
    @POST("/api/appapi/codeGet")
    suspend fun codeGet(
        @Field("username") username: String,
        @Field("img_verify") img_verify: String
    ): ApiResponse<Any>


//    /**
//     * 获取他人分享文章列表数据
//     */
//    @GET("user/{id}/share_articles/{page}/json")
//    suspend fun getShareByidData(
//        @Path("id") id: Int,
//        @Path("page") page: Int
//    ): ApiResponse<ShareResponse>


    /**
     * 添加一个TODO
     */
    @POST("/lg/todo/add/json")
    @FormUrlEncoded
    suspend fun addTodo(
        @Field("title") title: String,
        @Field("content") content: String,
        @Field("date") date: String,
        @Field("type") type: Int,
        @Field("priority") priority: Int
    ): ApiResponse<Any?>


    /**
     * 删除一个TODO
     */
    @POST("/lg/todo/delete/{id}/json")
    suspend fun deleteTodo(@Path("id") id: Int): ApiResponse<Any?>

    /**
     * 完成一个TODO
     */
    @POST("/lg/todo/done/{id}/json")
    @FormUrlEncoded
    suspend fun doneTodo(@Path("id") id: Int, @Field("status") status: Int): ApiResponse<Any?>

    @POST("/api/appapi/workOrder")
    @FormUrlEncoded
    suspend fun getGongdanCount(@Field("admin_id") admin_id: Int): ApiResponse<ArrayList<CountHome>>

    @POST("/api/appapi/deviceRun")
    @FormUrlEncoded
    suspend fun getDevice(@Field("admin_id") admin_id: Int): ApiResponse<ArrayList<CountHome>>

//    @POST("/api/appapi/patrolMapAdd")
//    @FormUrlEncoded
//    suspend fun mapAdd(
//        @Field("admin_id") admin_id: Int?,
//        @Field("work_type") work_type: String?,
//        @Field("mission_id") mission_id: String?,
//        @Field("id") id: String?,
//        @Field("type") type: String?,
//        @Field("upload_lnglat") upload_lnglat: String?
//    ): ApiResponse<Any>

    @GET("/api/appapi/addVerify")
    suspend fun getImage(): String

    @POST("/api/appapi/approveList")
    @FormUrlEncoded
    suspend fun getOrderList(
        @Field("admin_id") admin_id: Int,
        @Field("start_time") start_time: String?,
        @Field("end_time") end_time: String?,
        @Field("status") status: String?,
        @Field("limit") limit: String?,
        @Field("page") page: String?
    ): ApiResponse<OrderKt>

    @POST("/api/appapi/approveOwnList")
    @FormUrlEncoded
    suspend fun getMyReportOrderList(
        @Field("admin_id") admin_id: Int,
        @Field("device_id") device_id: String?,
        @Field("start_time") start_time: String?,
        @Field("end_time") end_time: String?,
        @Field("check_status") status: String?,//状态值 0全部 1待审批 2审批通过 3审批拒绝 4已完成
        @Field("keywords") keywords: String?,
        @Field("limit") limit: String?,
        @Field("page") page: String?
    ): ApiResponse<OrderKt>

    @POST("/api/appapi/patrolProblemList")
    @FormUrlEncoded
    suspend fun getXunjianList(
        @Field("admin_id") admin_id: Int,
        @Field("start_time") start_time: String?,
        @Field("end_time") end_time: String?,
        @Field("question_sta") status: String?,//状态值 0:未生成 1已生成
        @Field("keywords") keywords: String?,
        @Field("limit") limit: String?,
        @Field("page") page: String?
    ): ApiResponse<OrderKt>

    @POST("/api/appapi/approveDetail")
    @FormUrlEncoded
    suspend fun getOrderInfor(
        @Field("admin_id") admin_id: Int,
        @Field("id") id: String?

    ): ApiResponse<ArrayList<OrderKt>>

    @POST("/api/appapi/patrolProblemDetail")
    @FormUrlEncoded
    suspend fun getXunjianInfor(
        @Field("admin_id") admin_id: Int,
        @Field("id") id: String?

    ): ApiResponse<ArrayList<OrderKt>>

    @POST("/api/appapi/getProbleType")
    @FormUrlEncoded
    suspend fun getProblemType(@Field("pid") pid: String): ApiResponse<ArrayList<ProblemTypeKt>>

    @POST("/api/appapi/getFlowWorktypeDevice")
    @FormUrlEncoded
    suspend fun getDeviceTypeList(
        @Field("work_type") work_type: String,
        @Field("device_type") device_type: String,
        @Field("year") year: String,
        @Field("city") city: String,
        @Field("district") district: String,
        @Field("left_up_lng") left_up_lng: String,
        @Field("left_up_lat") left_up_lat: String,
        @Field("right_down_lng") right_down_lng: String,
        @Field("right_down_lat") right_down_lat: String
    ): ApiResponse<ArrayList<DeviceKt>>

    //    @GET
    //    Observable<BaseResponseJKM<SdMa>> sdMa(@Url String url, @Query("health_code") String health_code, @Query("app_id") String app_id, @Query("access_token") String access_token);
    @POST("/api/appapi/addFileWell")
    suspend fun upFileDevice(@Body multipartBody: RequestBody): ApiResponse<UpFileKt>

    @POST("/api/appapi/addFile")
    suspend fun upFile(@Body multipartBody: RequestBody): ApiResponse<UpFileKt>
    @POST("/api/appapi/addAppFIle")
    suspend fun upFileFeedBack(@Body multipartBody: RequestBody): ApiResponse<UpFileKt>

    @POST("/api/appapi/approveAdd")
    @FormUrlEncoded
    suspend fun reportAdd(
        @Field("question_sta") question_sta: String,
        @Field("form_type") form_type: String?,
        @Field("work_type") work_type: String?,
        @Field("son_type") son_type: String?,
        @Field("admin_id") admin_id: Int,
        @Field("device_id") device_id: String,
        @Field("upload_lnglat") upload_lnglat: String,
        @Field("address") address: String?,
        @Field("detail_type") detail_type: String,
        @Field("station_num") station_num: String?,
        @Field("approve_type") approve_type: String?,
        @Field("content") content: String,
        @Field("remark") remark: String?,
        @Field("file_ids") file_ids: String,
        @Field("copy_uids") copy_uids: String?
    ): ApiResponse<Any>

    @POST("/api/appapi/trackMapUnfinishList")
    @FormUrlEncoded
    suspend fun getTrackMapList(
        @Field("admin_id") admin_id: Int,
        @Field("work_type") work_type: String,
        @Field("mission_id") mission_id: String,
        @Field("id") id: String,
        @Field("limit") limit: String,
        @Field("page") page: String
    ): ApiResponse<OrderKt>

    @POST("/api/appapi/patrolMapAdd")
    @FormUrlEncoded
    suspend fun mapAdd(
        @Field("admin_id") admin_id: Int,
        @Field("work_type") work_type: String,
        @Field("mission_id") mission_id: String,
        @Field("id") id: String,
        @Field("type") type: String,
        @Field("upload_lnglat") upload_lnglat: String
    ): ApiResponse<Any>

    @POST("/api/appapi/getDeviceType")
    @FormUrlEncoded
    suspend fun getDeviceType(@Field("pid") pid: String): ApiResponse<ArrayList<ProblemTypeKt>>

    @POST("/api/appapi/getProjectDeviceType")
    @FormUrlEncoded
    suspend fun getProjectDeviceType(
        @Field("project_id") project_id: String,
        @Field("admin_id") admin_id: Int
    ): ApiResponse<ArrayList<ProblemTypeKt>>

    @POST("/api/appapi/getDepartmentUser")
    @FormUrlEncoded
    suspend fun getPerson(
        @Field("did") pid: String, @Field("admin_id") admin_id: Int,
        @Field("approve_sta") approve_sta: String = "1"
    ): ApiResponse<ArrayList<ProblemTypeKt>>


    @POST("/api/appapi/getCascadeDistrict")
    @FormUrlEncoded
    suspend fun getDistrict(@Field("parentid") pid: String): ApiResponse<ArrayList<DistrictKt>>

    @POST("/api/appapi/getWorktypeDeviceInfo")
    @FormUrlEncoded
    suspend fun getDeviceInfor(
        @Field("work_type") work_type: String,
        @Field("id") id: String?

    ): ApiResponse<ArrayList<DeviceKt>>

    @POST("/api/appapi/deviceTemp")
    @FormUrlEncoded
    suspend fun deviceAdd(
        @Field("operation_type") operation_type: String,
        @Field("device_id") device_id: String,
        @Field("work_type") work_type: String,
        @Field("device_type") device_type: String,
        @Field("project_id") project_id: String,
        @Field("name") name: String,
        @Field("num_code") num_code: String,
        @Field("device_status") device_status: String,
        @Field("question_sta") question_sta: String,
        @Field("upload_lnglat") upload_lnglat: String,
        @Field("address") address: String,
        @Field("username") username: String,
        @Field("phone") phone: String,
        @Field("thumb") thumb: String,
        @Field("file_ids") file_ids: String,
        @Field("province") province: String,
        @Field("city") city: String,
        @Field("district") district: String,
        @Field("boxcode") boxcode: String,
        @Field("imei") imei: String,
        @Field("changjia") changjia: String,
        @Field("year") year: String,
        @Field("buildtime") buildtime: String,
        @Field("admin_id") admin_id: Int,
        @Field("long_len") long_len: String,
        @Field("depth") depth: String,
        @Field("dn_norms") dn_norms: String,
        @Field("width_len") width_len: String,
        @Field("remark") remark: String,
        @Field("rongliang") rongliang: String,
        @Field("check_type") check_type: String,
        @Field("bianma_num") bianma_num: String,
        @Field("json_text") json_text: String,
        @Field("water_outlet_plug") water_outlet_plug: String
    ): ApiResponse<Any>

    @POST("/api/appapi/deviceTemp")
    @FormUrlEncoded
    suspend fun deviceAdd2(
        @Field("operation_type") operation_type: String,
        @Field("device_id") device_id: String,
        @Field("work_type") work_type: String,
        @Field("device_type") device_type: String,
        @Field("project_id") project_id: String,
        @Field("name") name: String,
        @Field("num_code") num_code: String,
        @Field("device_status") device_status: String,
        @Field("question_sta") question_sta: String,
        @Field("upload_lnglat") upload_lnglat: String,
        @Field("address") address: String,
        @Field("username") username: String,
        @Field("phone") phone: String,
        @Field("thumb") thumb: String,
        @Field("file_ids") file_ids: String,
        @Field("province") province: String,
        @Field("city") city: String,
        @Field("district") district: String,
        @Field("changjia") changjia: String,
        @Field("year") year: String,
        @Field("buildtime") buildtime: String,
        @Field("remark") remark: String,
        @Field("admin_id") admin_id: Int,
        @Field("json_text") json_text: String,
        @Field("boxcode") boxcode: String,
        @Field("imei") imei: String,
        @FieldMap fields: Map<String, String>
    ): ApiResponse<Any>

    @POST("/api/appapi/projectList")
    @FormUrlEncoded
    suspend fun getProjectList(
        @Field("admin_id") admin_id: Int,
        @Field("keywords") keywords: String,
        @Field("year") year: String,
        @Field("city_ids") city_ids: String,
        @Field("limit") limit: String,
        @Field("page") page: String
    ): ApiResponse<Project>

    @POST("/api/appapi/getSonTypeField")
    @FormUrlEncoded
    suspend fun getDeviceField(
        @Field("device_type") device_type: String
    ): ApiResponse<ArrayList<com.emapp.lccode.bean.Field>>

    @POST("/api/appapi/noFinishProject")
    @FormUrlEncoded
    suspend fun getUnFinishuProjectList(
        @Field("admin_id") admin_id: Int,
        @Field("keywords") keywords: String,
        @Field("limit") limit: String,
        @Field("page") page: String
    ): ApiResponse<ArrayList<Project>>

    @POST("/api/appapi/projectProgressList")
    @FormUrlEncoded
    suspend fun gongxuList(
        @Field("admin_id") admin_id: Int,
        @Field("device_id") device_id: String
    ): ApiResponse<ArrayList<Gongxu>>

    @POST("/api/appapi/approveAssign")
    @FormUrlEncoded
    suspend fun paidan(
        @Field("check") check: String,
        @Field("admin_id") admin_id: Int,
        @Field("id") id: String,
        @Field("check_admin_ids") check_admin_ids: String,
        @Field("type") type: String,
        @Field("check_node") check_node: String,
        @Field("approve_type") approve_type: String
    ): ApiResponse<Any>

    @POST("/api/appapi/materialList")
    @FormUrlEncoded
    suspend fun getWuliaoList(
        @Field("admin_id") admin_id: Int,
        @Field("keywords") keywords: String,
        @Field("limit") limit: String,
        @Field("page") page: String
    ): ApiResponse<MaterialKt>

    @POST("/api/appapi/flowCheck")
    @FormUrlEncoded
    suspend fun reply(
        @Field("check") check: String,
        @Field("admin_id") admin_id: Int,
        @Field("id") id: String,
        @Field("type") type: String,
        @Field("check_node") check_node: String,
        @Field("check_admin_ids") check_admin_ids: String,
        @Field("content") content: String,
        @Field("amount") amount: String,
        @Field("file_ids") file_ids: String,
        @Field("upload_bom") upload_bom: String
    ): ApiResponse<Any>
    @POST("/api/appapi/softwareAdd")
    @FormUrlEncoded
    suspend fun feedback(
        @Field("admin_id") admin_id: Int,
        @Field("content") content: String,
        @Field("remark") remark: String,
        @Field("file_ids") file_ids: String,
        @Field("app_type") check: String="1",
    ): ApiResponse<Any>
    @POST("/api/appapi/deviceTempList")
    @FormUrlEncoded
    suspend fun getDeviceList(
        @Field("admin_id") admin_id: Int,
        @Field("check_status") check_status: String,
        @Field("limit") limit: String = BaseConfig.page_count.toString(),
        @Field("page") page: String = "0"
    ): ApiResponse<DeviceKt>

    @POST("/api/appapi/getVersion")
    @FormUrlEncoded
    suspend fun getVersion(
        @Field("oldversion") oldversion: String
    ): ApiResponse<VersionKt>

    @POST("/api/appapi/getVersion")
    @FormUrlEncoded
    suspend fun getVersion2(
        @Field("oldversion") oldversion: String
    ): ApiResponse<Any>

    @GET("/storage/webjson/{path}")
    // @Streaming
    suspend fun getJsonMap(@Path("path") path: String): ResponseBody

    @POST("/api/appapi/deviceAdd")
    @FormUrlEncoded
    suspend fun projectDeviceAdd(
        @Field("project_id") project_id: String,
        @Field("name") name: String,
        @Field("num_code") num_code: String,
        @Field("upload_lnglat") upload_lnglat: String,
        @Field("json_text") json_text: String,
        @Field("city") city: String,
        @Field("district") district: String,
        @Field("address") address: String,
        @Field("work_type") work_type: String,
        @Field("device_type") device_type: String,
        @Field("build_status") build_status: String,
        @Field("star_time") star_time: String,
        @Field("scene_file_ids") scene_file_ids: String,
        @Field("admin_id") admin_id: Int,
        @Field("remark") remark: String,
        @Field("build_company") build_company: String,
        @FieldMap fields: Map<String, String>
    ): ApiResponse<Any>

    @POST("/api/appapi/deviceUpdate")
    @FormUrlEncoded
    suspend fun projectDeviceUpdate(
        @Field("id") id: String,
        @Field("device_id") device_id: String,
        @Field("project_id") project_id: String,
        @Field("name") name: String,
        @Field("num_code") num_code: String,
        @Field("upload_lnglat") upload_lnglat: String,
        @Field("json_text") json_text: String,
        @Field("city") city: String,
        @Field("district") district: String,
        @Field("address") address: String,
        @Field("work_type") work_type: String,
        @Field("device_type") device_type: String,
        @Field("build_status") build_status: String,
        @Field("star_time") star_time: String,
        @Field("buildtime") buildtime: String,
        @Field("scene_file_ids") scene_file_ids: String,
        @Field("file_ids") file_ids: String,
        @Field("admin_id") admin_id: Int,
        @Field("remark") remark: String,
        @Field("build_company") build_company: String,
        @FieldMap fields: Map<String, String>
    ): ApiResponse<Any>

    @POST("/api/appapi/deviceProjectList")
    @FormUrlEncoded
    suspend fun getProjectDeviceMapList(
        @Field("admin_id") admin_id: Int,
        @Field("project_id") project_id: String,
        @Field("device_type") device_type: String,
        @Field("build_status") build_status: String,
        @Field("keywords") keywords: String
    ): ApiResponse<ArrayList<DeviceKt>>

    @POST("/api/appapi/addSceneFile")
    suspend fun upFileProjectDevice(@Body multipartBody: RequestBody): ApiResponse<UpFileKt>

    @POST("/api/appapi/addFileWell")
    suspend fun upFileProjectDeviceComplete(@Body multipartBody: RequestBody): ApiResponse<UpFileKt>

    @POST("/api/appapi/progressAdd")
    @FormUrlEncoded
    suspend fun projectProgressAdd(
        @Field("admin_id") admin_id: Int,
        @Field("id") id: String,
        @Field("device_id") device_id: String,
        @Field("build_status") build_status: String,
        @Field("name") name: String,
        @Field("well_process_id") well_process_id: String,
        @Field("content") content: String,
        @Field("file_ids") file_ids: String,
        @Field("materials_file_ids") materials_file_ids: String,
        @Field("remark") remark: String

    ): ApiResponse<Any>

    @POST("/api/appapi/progressList")
    @FormUrlEncoded
    suspend fun getProgressList(
        @Field("admin_id") admin_id: Int,
        @Field("device_id") device_id: String
    ): ApiResponse<ArrayList<DeviceKt>>

    @POST("/api/appapi/progressDetail")
    @FormUrlEncoded
    suspend fun getProgressInfor(
        @Field("admin_id") admin_id: Int,
        @Field("id") id: String

    ): ApiResponse<ArrayList<DeviceKt>>

    @POST("/api/appapi/deviceProjectPageList")
    @FormUrlEncoded
    suspend fun getProjectDevicePageList(
        @Field("admin_id") admin_id: Int,
        @Field("project_id") project_id: String,
        @Field("device_type") device_type: String,
        @Field("build_status") build_status: String,
        @Field("keywords") keywords: String,
        @Field("limit") limit: String = BaseConfig.page_count.toString(),
        @Field("page") page: String = "0"
    ): ApiResponse<DeviceKt>

    @POST("/api/appapi/projectProgressStatistics")
    @FormUrlEncoded
    suspend fun getProjectProgressList(
        @Field("admin_id") admin_id: Int,
        @Field("project_id") project_id: String
    ): ApiResponse<Project>

    @POST("/api/appapi/getAmapKey")
    @FormUrlEncoded
    suspend fun getAmapKey(@Field("admin_id") admin_id: Int = 1): ApiResponse<Any>
}